package softswitch.ws;

import java.util.Date;
import java.util.List;

import javax.ejb.EJB;
import javax.ejb.Stateless;

import org.apache.poi.hssf.usermodel.HSSFFont;
import org.apache.poi.hssf.util.CellRangeAddress;
import org.apache.poi.hssf.util.HSSFColor;
import org.apache.poi.ss.usermodel.BorderStyle;
import org.apache.poi.ss.usermodel.CreationHelper;
import org.apache.poi.ss.usermodel.IndexedColors;
import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFCellStyle;
import org.apache.poi.xssf.usermodel.XSSFFont;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;

import security.model.Corporation;
import security.model.Organization;
import security.service.SecurityService;
import softswitch.model.CallDetail;
import softswitch.model.CallSummaryRouteGroup;
import softswitch.model.Circuit;
import softswitch.model.Package;
import softswitch.model.RouteGroup;
import softswitch.service.CallDetailService;
import softswitch.service.CallSummaryRouteGroupService;
import util.DateUtil;

@Stateless
public class ReportService {

    @EJB
    SoftswitchService softswitchService;

    @EJB
    SecurityService securityService;

    @EJB
    CallDetailService callDetailService;

    @EJB
    CallSummaryRouteGroupService callSummaryRouteGroupService;

    @EJB
    DateUtil dateUtil;

    Integer currentRow;

    XSSFWorkbook book;
    CreationHelper createHelper;

    public XSSFWorkbook getCallDetailReportByDateRangeCorporation(Corporation corporation, Date startdate, Date enddate, List<RouteGroup> routegroups) {
        return null;
    }

    public XSSFWorkbook getCallDetailReportByDateRangeOrganization(Organization organization, Date startdate, Date enddate, List<RouteGroup> routegroups) {
        return null;
    }

    public XSSFWorkbook getCallDetailReportByDateRangeCircuit(Circuit circuit, Date startdate, Date enddate, List<RouteGroup> routegroups) {

        book = new XSSFWorkbook();
        createHelper = book.getCreationHelper();

        XSSFSheet summary = book.createSheet("Resumen");
        XSSFSheet detail = book.createSheet("Detalle");
        summary.setPrintGridlines(false);

        List<CallDetail> calldetails = callDetailService.listByDateRange(circuit, startdate, enddate, routegroups, null, null, null, "ASC");
                
        //Llamar al metodo por range
        //summary = addCircuitSummaryMonth(circuit, startdate, enddate, routegroups, summary);
        detail = addDetail(calldetails, detail);

        return book;

    }
    
    
    public XSSFWorkbook getCallDetailReportByMonthCircuit(Circuit circuit, Date startdate, Date enddate, List<RouteGroup> routegroups) {

        book = new XSSFWorkbook();
        createHelper = book.getCreationHelper();

        XSSFSheet summary = book.createSheet("Resumen");
        XSSFSheet detail = book.createSheet("Detalle");
        summary.setPrintGridlines(false);

        List<CallDetail> calldetails = callDetailService.listByDateRange(circuit, startdate, enddate, routegroups, null, null, null, "ASC");
                
        summary = addCircuitSummaryMonth(circuit, startdate, enddate, routegroups, summary);
        detail = addDetail(calldetails, detail);

        return book;

    }

    public XSSFSheet addCircuitSummaryMonth(Circuit circuit, Date startdate, Date enddate, List<RouteGroup> routegroups, XSSFSheet sheet) {

        /*try {
            InputStream stream = FacesUtils.getResourceHandler().createResource("images/logo.png").getInputStream();

            Organization org = securityService.getDefaultOrganization();
            byte[] bytes;
            if (org.getLogo() == null) {
                bytes = IOUtils.toByteArray(stream);
            } else {
                bytes = org.getLogo();
            }

            Integer pictureIdx = book.addPicture(bytes, Workbook.PICTURE_TYPE_PNG);

            Drawing drawing = sheet.createDrawingPatriarch();
            ClientAnchor anchor = createHelper.createClientAnchor();
            anchor.setCol1(2);
            anchor.setRow1(1);
            Picture pict = drawing.createPicture(anchor, pictureIdx);
            pict.resize(0.45);

        } catch (IOException e) {
            e.printStackTrace();
        }*/

        XSSFFont headerfont = book.createFont();
        headerfont.setColor(HSSFColor.BLACK.index);
        headerfont.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
        headerfont.setFontHeight((short) 200);

        XSSFCellStyle headercellstyle2 = book.createCellStyle();
        headercellstyle2.setAlignment(XSSFCellStyle.ALIGN_CENTER);
        headercellstyle2.setBorderBottom(XSSFCellStyle.BORDER_THIN);
        headercellstyle2.setBorderTop(XSSFCellStyle.BORDER_THIN);
        headercellstyle2.setBorderRight(XSSFCellStyle.BORDER_THIN);
        headercellstyle2.setBorderLeft(XSSFCellStyle.BORDER_THIN);
        headercellstyle2.setVerticalAlignment(XSSFCellStyle.ALIGN_CENTER);
        headercellstyle2.setFont(headerfont);

        XSSFCellStyle headercellstyle = book.createCellStyle();
        headercellstyle.setAlignment(XSSFCellStyle.ALIGN_CENTER);
        headercellstyle.setFillForegroundColor(HSSFColor.GREY_40_PERCENT.index);
        headercellstyle.setFillPattern(XSSFCellStyle.SOLID_FOREGROUND);
        headercellstyle.setBorderBottom(XSSFCellStyle.BORDER_THIN);
        headercellstyle.setBorderTop(XSSFCellStyle.BORDER_THIN);
        headercellstyle.setBorderRight(XSSFCellStyle.BORDER_THIN);
        headercellstyle.setBorderLeft(XSSFCellStyle.BORDER_THIN);
        headercellstyle.setVerticalAlignment(XSSFCellStyle.ALIGN_CENTER);
        headercellstyle.setFont(headerfont);

        XSSFFont footerfont = book.createFont();
        footerfont.setColor(HSSFColor.WHITE.index);
        footerfont.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
        footerfont.setFontHeight((short) 200);

        XSSFCellStyle footercellstyle = book.createCellStyle();
        footercellstyle.setAlignment(XSSFCellStyle.ALIGN_CENTER);
        footercellstyle.setFillForegroundColor(HSSFColor.ORANGE.index);
        footercellstyle.setFillPattern(XSSFCellStyle.SOLID_FOREGROUND);
        footercellstyle.setBorderBottom(XSSFCellStyle.BORDER_THIN);
        footercellstyle.setBorderTop(XSSFCellStyle.BORDER_THIN);
        footercellstyle.setBorderRight(XSSFCellStyle.BORDER_THIN);
        footercellstyle.setBorderLeft(XSSFCellStyle.BORDER_THIN);
        footercellstyle.setVerticalAlignment(XSSFCellStyle.ALIGN_CENTER);
        footercellstyle.setFont(footerfont);

        XSSFCellStyle footercellstyleint = book.createCellStyle();
        footercellstyleint.setAlignment(XSSFCellStyle.ALIGN_RIGHT);
        footercellstyleint.setFillForegroundColor(HSSFColor.ORANGE.index);
        footercellstyleint.setFillPattern(XSSFCellStyle.SOLID_FOREGROUND);
        footercellstyleint.setBorderBottom(XSSFCellStyle.BORDER_THIN);
        footercellstyleint.setBorderTop(XSSFCellStyle.BORDER_THIN);
        footercellstyleint.setBorderRight(XSSFCellStyle.BORDER_THIN);
        footercellstyleint.setBorderLeft(XSSFCellStyle.BORDER_THIN);
        footercellstyleint.setVerticalAlignment(XSSFCellStyle.ALIGN_CENTER);
        footercellstyleint.setDataFormat(createHelper.createDataFormat().getFormat("#,##0"));
        footercellstyleint.setFont(footerfont);

        XSSFCellStyle footercellstyledec = book.createCellStyle();
        footercellstyledec.setAlignment(XSSFCellStyle.ALIGN_RIGHT);
        footercellstyledec.setFillForegroundColor(HSSFColor.ORANGE.index);
        footercellstyledec.setFillPattern(XSSFCellStyle.SOLID_FOREGROUND);
        footercellstyledec.setBorderBottom(XSSFCellStyle.BORDER_THIN);
        footercellstyledec.setBorderTop(XSSFCellStyle.BORDER_THIN);
        footercellstyledec.setBorderRight(XSSFCellStyle.BORDER_THIN);
        footercellstyledec.setBorderLeft(XSSFCellStyle.BORDER_THIN);
        footercellstyledec.setVerticalAlignment(XSSFCellStyle.ALIGN_CENTER);
        footercellstyledec.setDataFormat(createHelper.createDataFormat().getFormat("#,##0.00"));
        footercellstyledec.setFont(footerfont);

        XSSFFont totalfont = book.createFont();
        totalfont.setColor(HSSFColor.WHITE.index);
        totalfont.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
        totalfont.setFontHeight((short) 200);

        XSSFCellStyle totalcellstyle = book.createCellStyle();
        totalcellstyle.setAlignment(XSSFCellStyle.ALIGN_CENTER);
        totalcellstyle.setFillForegroundColor(HSSFColor.ORANGE.index);
        totalcellstyle.setFillPattern(XSSFCellStyle.SOLID_FOREGROUND);
        totalcellstyle.setBorderBottom(XSSFCellStyle.BORDER_THIN);
        totalcellstyle.setBorderTop(XSSFCellStyle.BORDER_THIN);
        totalcellstyle.setBorderRight(XSSFCellStyle.BORDER_THIN);
        totalcellstyle.setBorderLeft(XSSFCellStyle.BORDER_THIN);
        totalcellstyle.setVerticalAlignment(XSSFCellStyle.ALIGN_CENTER);
        totalcellstyle.setDataFormat(createHelper.createDataFormat().getFormat("#,##0.00"));
        totalcellstyle.setFont(totalfont);

        XSSFCellStyle zeroDigitsCellStyle = book.createCellStyle();
        zeroDigitsCellStyle.setDataFormat(createHelper.createDataFormat().getFormat("#,##"));

        XSSFCellStyle twoDigitsCellStyle = book.createCellStyle();
        twoDigitsCellStyle.setDataFormat(createHelper.createDataFormat().getFormat("#,##0.00"));

        XSSFCellStyle treeDigitsCellStyle = book.createCellStyle();
        treeDigitsCellStyle.setDataFormat(createHelper.createDataFormat().getFormat("#,##0.000"));

        //------------------------------------------------------------------------------------------
        Organization organization = securityService.getOrganizationById(circuit.getOrganization_id());

        //HEADER BY CIRCUIT
        currentRow = 3;
        XSSFRow h1rowClient = sheet.createRow(currentRow);
        XSSFCell h1cellClientLabel = h1rowClient.createCell(0);
        h1cellClientLabel.setCellValue("CLIENTE:");
        h1cellClientLabel.setCellStyle(headercellstyle2);

        XSSFCell h1cellClient = h1rowClient.createCell(1);
        h1cellClient.setCellValue(organization.getName());
        h1cellClient.setCellStyle(headercellstyle2);
        
        sheet.addMergedRegion(new CellRangeAddress(3,3,1,2));

        currentRow++;
        XSSFRow h1rowPeriod = sheet.createRow(currentRow);
        XSSFCell h1cellPeriodLabel = h1rowPeriod.createCell(0);
        h1cellPeriodLabel.setCellValue("PERIODO");
        h1cellPeriodLabel.setCellStyle(headercellstyle2);

        XSSFCell h1cellPeriod = h1rowPeriod.createCell(1);
        h1cellPeriod.setCellValue(dateUtil.getMonthName(startdate) + "-" + dateUtil.getYear(startdate) );
        h1cellPeriod.setCellStyle(headercellstyle2);
        
        
        currentRow++;
        currentRow++;

        XSSFRow h1row1 = sheet.createRow(currentRow);

        XSSFCell h1cell1 = h1row1.createCell(0);
        h1cell1.setCellStyle(headercellstyle);
        h1cell1.setCellValue("Numeros Telefonicos");

        XSSFCell h1cell2 = h1row1.createCell(1);
        h1cell2.setCellStyle(headercellstyle);
        h1cell2.setCellValue("Cantidad");

        XSSFCell h1cell3 = h1row1.createCell(2);
        h1cell3.setCellStyle(headercellstyle);
        h1cell3.setCellValue("Precio S/.");

        Double totalTime = 0.00;
        Double totalCost = 0.00;
        Double totalCostFinal = 0.00;

        currentRow++;

        Long numberdids = softswitchService.getDidTotalItemsByCircuit(circuit);
        Double pricedids = softswitchService.getDidTotalPriceByCircuit(circuit);

        if (numberdids == null) {
            numberdids = new Long(0);
            pricedids = 0.0;
        } else {
            if (pricedids == null) {
                pricedids = 0.0;
            } else {
                totalCostFinal = totalCostFinal + pricedids;
            }

        }

        XSSFRow f1row1 = sheet.createRow(currentRow);
        XSSFCell f1cell1 = f1row1.createCell(0);
        f1cell1.setCellStyle(footercellstyle);
        f1cell1.setCellValue("Numeracion DID");

        XSSFCell f1cell2 = f1row1.createCell(1);
        f1cell2.setCellStyle(footercellstyleint);
        f1cell2.setCellValue(numberdids);

        XSSFCell f1cell3 = f1row1.createCell(2);
        f1cell3.setCellStyle(footercellstyledec);
        f1cell3.setCellValue(pricedids);

        currentRow++;
        currentRow++;

        //-----------------------------------------------------------------------------
        XSSFRow h2row1 = sheet.createRow(currentRow);

        XSSFCell h2cell1 = h2row1.createCell(0);
        h2cell1.setCellStyle(headercellstyle);
        h2cell1.setCellValue("Bolsa de Minutos");

        XSSFCell h2cell2 = h2row1.createCell(1);
        h2cell2.setCellStyle(headercellstyle);
        h2cell2.setCellValue("Minutos");

        XSSFCell h2cell3 = h2row1.createCell(2);
        h2cell3.setCellStyle(headercellstyle);
        h2cell3.setCellValue("Precio S/.");

        totalTime = 0.00;
        totalCost = 0.00;

        for (Package packag : softswitchService.listPackagesByCircuit(circuit)) {

            currentRow++;
            XSSFRow row = sheet.createRow(currentRow);

            XSSFCell cell1 = row.createCell(0);
            cell1.setCellValue(packag.getOffer().getName());

            XSSFCell cell2 = row.createCell(1);
            cell2.setCellStyle(zeroDigitsCellStyle);
            cell2.setCellValue(packag.getOffer().getMinutes());
            totalTime = totalTime + packag.getOffer().getMinutes();

            XSSFCell cell3 = row.createCell(2);
            cell3.setCellStyle(twoDigitsCellStyle);
            cell3.setCellValue(packag.getOffer().getCost());
            totalCost = totalCost + packag.getOffer().getCost();
        }

        totalCostFinal = totalCostFinal + totalCost;

        currentRow++;

        XSSFRow f2row1 = sheet.createRow(currentRow);
        XSSFCell f2cell1 = f2row1.createCell(0);
        f2cell1.setCellStyle(footercellstyle);
        f2cell1.setCellValue("SubTotal");

        XSSFCell f2cell2 = f2row1.createCell(1);
        f2cell2.setCellStyle(footercellstyleint);
        f2cell2.setCellValue(totalTime);

        XSSFCell f2cell3 = f2row1.createCell(2);
        f2cell3.setCellStyle(footercellstyledec);
        f2cell3.setCellValue(totalCost);

        currentRow++;
        currentRow++;

        //-----------------------------------------------------------------------------
        XSSFRow h3row2 = sheet.createRow(currentRow);

        XSSFCell h3cell1 = h3row2.createCell(0);
        h3cell1.setCellStyle(headercellstyle);
        h3cell1.setCellValue("Consumo por Destino");

        XSSFCell h3cell2 = h3row2.createCell(1);
        h3cell2.setCellStyle(headercellstyle);
        h3cell2.setCellValue("Tiempo (Min)");

        XSSFCell h3cell3 = h3row2.createCell(2);
        h3cell3.setCellStyle(headercellstyle);
        h3cell3.setCellValue("Total S/.");

        totalTime = 0.00;
        totalCost = 0.00;

        for (RouteGroup routegroup : routegroups) {
            double subtotalTime = 0.0;
            double subtotalCost = 0.0;
            CallSummaryRouteGroup callSummaryRouteGroup = callSummaryRouteGroupService.getByDate(startdate, circuit, routegroup);
            if (callSummaryRouteGroup != null) {
                subtotalTime = callSummaryRouteGroup.getTime();
                subtotalCost = callSummaryRouteGroup.getCost();
                totalTime = totalTime + subtotalTime;
                totalCost = totalCost + subtotalCost;
            }

            currentRow++;
            XSSFRow row = sheet.createRow(currentRow);

            XSSFCell cell1 = row.createCell(0);
            cell1.setCellValue(routegroup.getName());

            XSSFCell cell2 = row.createCell(1);
            cell2.setCellStyle(twoDigitsCellStyle);
            cell2.setCellValue(subtotalTime);

            XSSFCell cell3 = row.createCell(2);
            cell3.setCellStyle(twoDigitsCellStyle);
            cell3.setCellValue(subtotalCost);

        }

        totalCostFinal = totalCostFinal + totalCost;

        //-----------XXXXXXXXXXXXXXX-----------------------
        currentRow++;

        XSSFRow f3row = sheet.createRow(currentRow);
        XSSFCell f3cell1 = f3row.createCell(0);
        f3cell1.setCellStyle(footercellstyle);
        f3cell1.setCellValue("SubTotal");

        XSSFCell f3cell2 = f3row.createCell(1);
        f3cell2.setCellStyle(footercellstyledec);
        f3cell2.setCellValue(totalTime);

        XSSFCell f3cell3 = f3row.createCell(2);
        f3cell3.setCellStyle(footercellstyledec);
        f3cell3.setCellValue(totalCost);

        currentRow++;
        currentRow++;

        //-----------------------------------------------------------------------------
        XSSFRow c1row = sheet.createRow(currentRow);
        XSSFCell c1cell1 = c1row.createCell(0);
        c1cell1.setCellValue("Nota:");

        currentRow++;
        XSSFRow c2row = sheet.createRow(currentRow);
        XSSFCell c2cell1 = c2row.createCell(0);
        c2cell1.setCellValue("Monto en Nuevos Soles");
        XSSFCell c2cell2 = c2row.createCell(1);
        c2cell2.setCellStyle(totalcellstyle);
        c2cell2.setCellValue("TOTAL");
        XSSFCell c2cell3 = c2row.createCell(2);
        c2cell3.setCellStyle(totalcellstyle);
        c2cell3.setCellValue(totalCostFinal);

        currentRow++;
        XSSFRow c3row = sheet.createRow(currentRow);
        XSSFCell c3cell1 = c3row.createCell(0);
        c3cell1.setCellValue("No Incluye IGV");

        //Setting Columns With
        sheet.setColumnWidth(0, 7000);
        sheet.setColumnWidth(1, 6000);
        sheet.setColumnWidth(2, 4000);
        sheet.setColumnWidth(3, 4000);
        sheet.setColumnWidth(3, 2000);

        XSSFCellStyle style1 = book.createCellStyle();
        style1.setBorderBottom(BorderStyle.THIN);
        style1.setBottomBorderColor(IndexedColors.BLUE.getIndex());
        style1.setBorderLeft(BorderStyle.THIN);
        style1.setBorderRight(BorderStyle.THIN);
        style1.setBorderTop(BorderStyle.THIN);

        return sheet;
    }

    public XSSFSheet addDetail(List<CallDetail> calldetails, XSSFSheet sheet) {

        /* try {
         //InputStream is = new FileInputStream("/home/xdmian/devel/workspace/virtualskynet/web/resources/images/logo.png");
         InputStream stream = new FileInputStream("/home/xdmian/devel/workspace/asterisk360/web/resources/images/logo.png ");

         Organization org = securityService.getDefaultOrganization();
         byte[] bytes;
         if (org.getLogo() == null) {
         bytes = IOUtils.toByteArray(stream);
         }
         else {
         bytes = org.getLogo();
         }

         int pictureIdx = book.addPicture(bytes, Workbook.PICTURE_TYPE_PNG);

         Drawing drawing = sheet.createDrawingPatriarch();
         ClientAnchor anchor = createHelper.createClientAnchor();
         anchor.setCol1(1);
         anchor.setRow1(1);
         Picture pict = drawing.createPicture(anchor, pictureIdx);
         pict.resize(0.7);

         }
         catch (IOException e) {
         e.printStackTrace();
         }*/
        XSSFFont headerfont = book.createFont();
        headerfont.setColor(HSSFColor.BLACK.index);
        headerfont.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
        headerfont.setFontHeight((short) 200);

        XSSFCellStyle headercellstyle = book.createCellStyle();
        headercellstyle.setAlignment(XSSFCellStyle.ALIGN_CENTER);
        headercellstyle.setFillForegroundColor(HSSFColor.ORANGE.index);
        headercellstyle.setFillPattern(XSSFCellStyle.SOLID_FOREGROUND);
        headercellstyle.setBorderBottom(XSSFCellStyle.BORDER_THIN);
        headercellstyle.setBorderTop(XSSFCellStyle.BORDER_THIN);
        headercellstyle.setBorderRight(XSSFCellStyle.BORDER_THIN);
        headercellstyle.setBorderLeft(XSSFCellStyle.BORDER_THIN);
        headercellstyle.setVerticalAlignment(XSSFCellStyle.ALIGN_CENTER);
        headercellstyle.setFont(headerfont);

        XSSFCellStyle zeroDigitsCellStyle = book.createCellStyle();
        zeroDigitsCellStyle.setDataFormat(createHelper.createDataFormat().getFormat("#,##"));

        XSSFCellStyle twoDigitsCellStyle = book.createCellStyle();
        twoDigitsCellStyle.setDataFormat(createHelper.createDataFormat().getFormat("#,##0.00"));

        XSSFCellStyle treeDigitsCellStyle = book.createCellStyle();
        treeDigitsCellStyle.setDataFormat(createHelper.createDataFormat().getFormat("#,##0.000"));

        currentRow = 0;

        XSSFRow filaCabecera = sheet.createRow(currentRow);

        XSSFCell headcell0 = filaCabecera.createCell(0);
        headcell0.setCellStyle(headercellstyle);
        headcell0.setCellValue("Fecha");

        XSSFCell headcell1 = filaCabecera.createCell(1);
        headcell1.setCellStyle(headercellstyle);
        headcell1.setCellValue("Hora");

        XSSFCell headcell2 = filaCabecera.createCell(2);
        headcell2.setCellStyle(headercellstyle);
        headcell2.setCellValue("Origen");

        XSSFCell headcell3 = filaCabecera.createCell(3);
        headcell3.setCellStyle(headercellstyle);
        headcell3.setCellValue("Destino");

        XSSFCell headcell4 = filaCabecera.createCell(4);
        headcell4.setCellStyle(headercellstyle);
        headcell4.setCellValue("Descripcion");

        XSSFCell headcell5 = filaCabecera.createCell(5);
        headcell5.setCellStyle(headercellstyle);
        headcell5.setCellValue("Tiempo (Min)");

        XSSFCell headcell6 = filaCabecera.createCell(6);
        headcell6.setCellStyle(headercellstyle);
        headcell6.setCellValue("Tarifa S/.");

        XSSFCell headcell7 = filaCabecera.createCell(7);
        headcell7.setCellStyle(headercellstyle);
        headcell7.setCellValue("Total S/.");

        for (CallDetail calldetail : calldetails) {
            currentRow++;
            XSSFRow fila = sheet.createRow(currentRow);

            XSSFCell cell0 = fila.createCell(0);
            cell0.setCellValue(dateUtil.splitDate(calldetail.getCalldate()));

            XSSFCell cell1 = fila.createCell(1);
            cell1.setCellValue(dateUtil.splitTime(calldetail.getCalldate()));

            XSSFCell cell2 = fila.createCell(2);
            cell2.setCellValue(calldetail.getSource());

            XSSFCell cell3 = fila.createCell(3);
            cell3.setCellValue(calldetail.getDestination());

            XSSFCell cell4 = fila.createCell(4);
            cell4.setCellValue(calldetail.getRoute().getName());

            XSSFCell cell5 = fila.createCell(5);
            cell5.setCellStyle(twoDigitsCellStyle);
            cell5.setCellValue(((double) calldetail.getTime()) / 60);

            XSSFCell cell6 = fila.createCell(6);
            cell6.setCellStyle(treeDigitsCellStyle);
            cell6.setCellValue(calldetail.getSellrate());

            XSSFCell cell7 = fila.createCell(7);
            cell7.setCellStyle(treeDigitsCellStyle);
            cell7.setCellValue(calldetail.getSellcost());

        }

        //Setting Columns With
        sheet.setColumnWidth(0, 4000);
        sheet.setColumnWidth(1, 4000);
        sheet.setColumnWidth(2, 4000);
        sheet.setColumnWidth(3, 4000);
        sheet.setColumnWidth(4, 8000);
        sheet.setColumnWidth(5, 3000);
        sheet.setColumnWidth(6, 3000);
        sheet.setColumnWidth(7, 3000);

        return sheet;

    }

}